package com.bawei.viewgroper;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private EditText showExit;
    private Button showBotton;
    private TagerViewGrop tagsLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        ViewGroup.MarginLayoutParams layoutParams =new ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.WRAP_CONTENT,ViewGroup.MarginLayoutParams.WRAP_CONTENT);
        showBotton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (showExit.getText().toString().length()!=0)
                {
                    TextView textView = new TextView(MainActivity.this);
                    textView.setText(showExit.getText().toString());
                    textView.setTextColor(Color.WHITE);
                    textView.setBackgroundColor(Color.BLUE);
                    tagsLayout.addView(textView,layoutParams);
                    showExit.setText("");
                }
            }
        });
    }

    private void initView() {
        showExit = findViewById(R.id.show_exit);
        showBotton = findViewById(R.id.show_botton);
        tagsLayout = findViewById(R.id.tags_layout);
    }
}